package com.wechatpay.v3.service;

import com.wechatpay.v3.sdk.WechatPay;
import com.wechatpay.v3.vo.UnifiedOrderResult;
import com.wechatpay.v3.vo.UnifiedOrderVo;
import com.wechatpay.v3.vo.WechatResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;


/**
 * @author liuyi <liuy@pvc123.com>
 * @since 2021/7/29
 */
public abstract class AbstractWechatPayProducer {

    private WechatPay wechatPay;

    @Autowired(required = false)
    @Qualifier("wechatPay")
    public void setWechatPay(WechatPay wechatPay) {
        this.wechatPay = wechatPay;
    }

    public abstract String getNotifyOrderCallbackUrl();

    public abstract String getNotifyRefundCallbackUrl();

    public void test() {

        System.out.println("wechatPay running");
    }

    public UnifiedOrderResult jsapi(UnifiedOrderVo vo) {

        try {
            return wechatPay.unifiedOrder(vo);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

    public WechatResult queryOrder(String outTradeNo) {

        try {
            return wechatPay.queryOrder(outTradeNo);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }

}
